# -*- coding: utf-8 -*-
# FileName:     zqueue.py
# time:         22/11/26 026 下午 3:12
# Author:       Zhou Hang
# Description:  I don't want to write
from src.custom_control.key_label import KeyLabel


class ZQueue:
    def __init__(self, max_length=10):
        self.q = []
        self.length = 0
        self.max_length = max_length

    def can_push(self):
        return self.length < self.max_length

    def can_pop(self):
        return self.length > 0

    def push(self, key_lbl):
        assert isinstance(key_lbl, KeyLabel)
        if not self.can_push():
            self.pop()
        self.q.append(key_lbl)
        self.length += 1

    def pop(self):
        if self.can_pop():
            self.length -= 1
            return self.q.pop(0)

    def for_each_label(self):
        """从队列头到尾遍历"""
        for i in range(self.length):
            yield self.q[i]

    def get_latest(self):
        if self.can_pop():
            return self.q[-1]
        return None


def main():
    pass


if __name__ == "__main__":
    main()
